<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">
<meta name="generator" content="Hexo 4.2.1">
  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16.png">
  <link rel="mask-icon" href="/images/logo.svg" color="#222">

<link rel="stylesheet" href="/css/main.css">


<link rel="stylesheet" href="/lib/font-awesome/css/all.min.css">

<script id="hexo-configurations">
    var NexT = window.NexT || {};
    var CONFIG = {"hostname":"www.lixiaofei.cn","root":"/","scheme":"Mist","version":"7.8.0","exturl":false,"sidebar":{"position":"left","display":"post","padding":18,"offset":12,"onmobile":false},"copycode":{"enable":false,"show_result":false,"style":null},"back2top":{"enable":true,"sidebar":false,"scrollpercent":false},"bookmark":{"enable":false,"color":"#222","save":"auto"},"fancybox":false,"mediumzoom":false,"lazyload":false,"pangu":false,"comments":{"style":"tabs","active":true,"storage":true,"lazyload":true,"nav":{"valine":{"order":-1}}},"algolia":{"hits":{"per_page":10},"labels":{"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}},"localsearch":{"enable":false,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false},"motion":{"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}}};
  </script>

  <meta name="description" content="上一期，谈了如何用 Python 打造运营系统 的过程，虽然以及很方便了，但是还有很多需要人工执行的地方，不是特别方便。 更重要的是无法及时为大家提供实时数据，加上有时工作繁忙可以忘掉，实属不便。 那么再进一步 —— 做成在线版的，可以随时浏览，方便快捷，还等什么，开干吧。">
<meta property="og:type" content="article">
<meta property="og:title" content="只需一招，Python 将系统秒变在线版！">
<meta property="og:url" content="http://www.lixiaofei.cn/2021-08-12-python-op-web/index.html">
<meta property="og:site_name" content="管窥程序">
<meta property="og:description" content="上一期，谈了如何用 Python 打造运营系统 的过程，虽然以及很方便了，但是还有很多需要人工执行的地方，不是特别方便。 更重要的是无法及时为大家提供实时数据，加上有时工作繁忙可以忘掉，实属不便。 那么再进一步 —— 做成在线版的，可以随时浏览，方便快捷，还等什么，开干吧。">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="http://www.lixiaofei.cn/images/2021/08/python_op_2/01.png">
<meta property="og:image" content="http://www.lixiaofei.cn/images/2021/08/python_op_2/02.png">
<meta property="article:published_time" content="2021-08-11T16:00:00.000Z">
<meta property="article:modified_time" content="2021-08-19T07:10:46.415Z">
<meta property="article:author" content="太阳雪">
<meta property="article:tag" content="Python">
<meta property="article:tag" content="编程">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="http://www.lixiaofei.cn/images/2021/08/python_op_2/01.png">

<link rel="canonical" href="http://www.lixiaofei.cn/2021-08-12-python-op-web/">


<script id="page-configurations">
  // https://hexo.io/docs/variables.html
  CONFIG.page = {
    sidebar: "",
    isHome : false,
    isPost : true,
    lang   : 'zh-CN'
  };
</script>

  <title>只需一招，Python 将系统秒变在线版！ | 管窥程序</title>
  






  <noscript>
  <style>
  .use-motion .brand,
  .use-motion .menu-item,
  .sidebar-inner,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-header { opacity: initial; }

  .use-motion .site-title,
  .use-motion .site-subtitle {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line-before i { left: initial; }
  .use-motion .logo-line-after i { right: initial; }
  </style>
</noscript>

</head>

<body itemscope itemtype="http://schema.org/WebPage">
  <div class="container use-motion">
    <div class="headband"></div>

    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏">
      <span class="toggle-line toggle-line-first"></span>
      <span class="toggle-line toggle-line-middle"></span>
      <span class="toggle-line toggle-line-last"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/" class="brand" rel="start">
      <span class="logo-line-before"><i></i></span>
      <h1 class="site-title">管窥程序</h1>
      <span class="logo-line-after"><i></i></span>
    </a>
      <p class="site-subtitle" itemprop="description">Today is a gift</p>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger">
    </div>
  </div>
</div>




<nav class="site-nav">
  <ul id="menu" class="main-menu menu">
        <li class="menu-item menu-item-home">

    <a href="/" rel="section"><i class="fa fa-home fa-fw"></i>首页</a>

  </li>
        <li class="menu-item menu-item-about">

    <a href="/about/" rel="section"><i class="fa fa-user fa-fw"></i>关于</a>

  </li>
        <li class="menu-item menu-item-tags">

    <a href="/tags/" rel="section"><i class="fa fa-tags fa-fw"></i>标签</a>

  </li>
        <li class="menu-item menu-item-categories">

    <a href="/categories/" rel="section"><i class="fa fa-th fa-fw"></i>分类</a>

  </li>
        <li class="menu-item menu-item-archives">

    <a href="/archives/" rel="section"><i class="fa fa-archive fa-fw"></i>归档</a>

  </li>
  </ul>
</nav>




</div>
    </header>

    
  <div class="back-to-top">
    <i class="fa fa-arrow-up"></i>
    <span>0%</span>
  </div>
  <div class="reading-progress-bar"></div>

  <a href="https://github.com/alisx" class="github-corner" title="Follow me on GitHub" aria-label="Follow me on GitHub" rel="noopener" target="_blank"><svg width="80" height="80" viewBox="0 0 250 250" aria-hidden="true"><path d="M0,0 L115,115 L130,115 L142,142 L250,250 L250,0 Z"></path><path d="M128.3,109.0 C113.8,99.7 119.0,89.6 119.0,89.6 C122.0,82.7 120.5,78.6 120.5,78.6 C119.2,72.0 123.4,76.3 123.4,76.3 C127.3,80.9 125.5,87.3 125.5,87.3 C122.9,97.6 130.6,101.9 134.4,103.2" fill="currentColor" style="transform-origin: 130px 106px;" class="octo-arm"></path><path d="M115.0,115.0 C114.9,115.1 118.7,116.5 119.8,115.4 L133.7,101.6 C136.9,99.2 139.9,98.4 142.2,98.6 C133.8,88.0 127.5,74.4 143.8,58.0 C148.5,53.4 154.0,51.2 159.7,51.0 C160.3,49.4 163.2,43.6 171.4,40.1 C171.4,40.1 176.1,42.5 178.8,56.2 C183.1,58.6 187.2,61.8 190.9,65.4 C194.5,69.0 197.7,73.2 200.1,77.6 C213.8,80.2 216.3,84.9 216.3,84.9 C212.7,93.1 206.9,96.0 205.4,96.6 C205.1,102.4 203.0,107.8 198.3,112.5 C181.9,128.9 168.3,122.5 157.7,114.1 C157.9,116.9 156.7,120.9 152.7,124.9 L141.0,136.5 C139.8,137.7 141.6,141.9 141.8,141.8 Z" fill="currentColor" class="octo-body"></path></svg></a>


    <main class="main">
      <div class="main-inner">
        <div class="content-wrap">
          

          <div class="content post posts-expand">
            

    
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="http://www.lixiaofei.cn/2021-08-12-python-op-web/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.png">
      <meta itemprop="name" content="太阳雪">
      <meta itemprop="description" content="总结 技术 思考 想法">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="管窥程序">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          只需一招，Python 将系统秒变在线版！
        </h1>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-calendar"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2021-08-12 00:00:00" itemprop="dateCreated datePublished" datetime="2021-08-12T00:00:00+08:00">2021-08-12</time>
            </span>
              <span class="post-meta-item">
                <span class="post-meta-item-icon">
                  <i class="far fa-calendar-check"></i>
                </span>
                <span class="post-meta-item-text">更新于</span>
                <time title="修改时间：2021-08-19 15:10:46" itemprop="dateModified" datetime="2021-08-19T15:10:46+08:00">2021-08-19</time>
              </span>

          
            <span id="/2021-08-12-python-op-web/" class="post-meta-item leancloud_visitors" data-flag-title="只需一招，Python 将系统秒变在线版！" title="阅读次数">
              <span class="post-meta-item-icon">
                <i class="fa fa-eye"></i>
              </span>
              <span class="post-meta-item-text">阅读次数：</span>
              <span class="leancloud-visitors-count"></span>
            </span>
  
  <span class="post-meta-item">
    
      <span class="post-meta-item-icon">
        <i class="far fa-comment"></i>
      </span>
      <span class="post-meta-item-text">Valine：</span>
    
    <a title="valine" href="/2021-08-12-python-op-web/#valine-comments" itemprop="discussionUrl">
      <span class="post-comments-count valine-comment-count" data-xid="/2021-08-12-python-op-web/" itemprop="commentCount"></span>
    </a>
  </span>
  
  

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
        <p>上一期，谈了如何用 <a href="https://mp.weixin.qq.com/s/oeMxd6a6aLzTr0xEIsUBRw" target="_blank" rel="noopener">Python 打造运营系统</a> 的过程，虽然以及很方便了，但是还有很多需要人工执行的地方，不是特别方便。</p>
<p>更重要的是无法及时为大家提供实时数据，加上有时工作繁忙可以忘掉，实属不便。</p>
<p>那么再进一步 —— 做成在线版的，可以随时浏览，方便快捷，还等什么，开干吧。<br><a id="more"></a></p>
<h2 id="规划"><a href="#规划" class="headerlink" title="规划"></a>规划</h2><p>上一期，做的工作主要是数据整合，数据处理，报表数据输出，已经做了大部分工作，现在的问题是如何 Web 化。</p>
<p>Web 化的主要目的是，让用户通过浏览器访问到报表数据，所以改造的重点在于将数据展示部分的用前端技术实现。</p>
<p>于是需要做的是，设计<strong>展示页面</strong>，定义与后端的 <strong>数据接口</strong>，选择服务器 <strong>部署</strong>。</p>
<p>而其中重点的工作是 展示页面 和 数据接口。</p>
<p>再进行具体工作之前，还有个一个重要工作就是 —— <strong>选择技术路线</strong>，即用什么技术做 Web 化实现。</p>
<p>那需要基于 Python 的 Web 框架来说，可以选择 Flask 和 Django。</p>
<p>鉴于项目比较小，另外之前写了一系列 <a href="https://mp.weixin.qq.com/s/jBom8hpmypTvdZLeZD-s_A" target="_blank" rel="noopener" title="Flask">Flask 的文章</a>，对 Flask 比较熟，所以选择了 Flask。</p>
<p>然后将之前实现的功能作为 Web 项目的外部模块引入，承担数据读取任务。</p>
<p>因为 Web 服务主要是通过数据读取的，对于打卡数据的抓取，和成员积分的计算，需要定时任务来完成，虽然可以在 Web 服务中利用 scheduled 来写计划任务，为了简便，直接使用 Linux 服务的 <a href="https://www.runoob.com/linux/linux-comm-crontab.html" target="_blank" rel="noopener" title="crontab">crontab</a> 命令来定时执行。</p>
<h2 id="展示页面"><a href="#展示页面" class="headerlink" title="展示页面"></a>展示页面</h2><p>之前写过一篇 <a href="https://mp.weixin.qq.com/s/KOYN8fxHoT0XDyJhLvuvkQ" target="_blank" rel="noopener">nginx 日志可视化</a>，其中用的是 Bootstrap 的前端框架，直接拿来用。</p>
<blockquote>
<p>真是，平时多积累，用时显身手！</p>
</blockquote>
<p>需要的页面有 打卡页面、成员数据、组长数据、开单记录。</p>
<p>从哪里开始呢？不是具体的页面，而是从制作模板页面开始。</p>
<h3 id="模板页面"><a href="#模板页面" class="headerlink" title="模板页面"></a>模板页面</h3><p>实现前台功能，比较省力的方式是使用模板，即，将页面共同的元素写在模板上，以重复利用。</p>
<p>创建一个页面模板 <code>layout.html</code>，模板中写完页面主题框架，以及引入 css，js 文件，并且为可替换部分预留区域。</p>
<p>可替换部分有，样式，导航菜单、主体页面、脚本。</p>
<p>因为最后是用 Flask 作为 Web 服务的，所以采用 <a href="https://jinja.palletsprojects.com/en/3.0.x/" target="_blank" rel="noopener" title="Jinja2 模板引擎">Jinja2</a> 做为模板引擎。</p>
<p>代码大致如下：</p>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br></pre></td><td class="code"><pre><span class="line">&#123;#</span><br><span class="line"><span class="meta">&lt;!DOCTYPE <span class="meta-keyword">html</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">html</span> <span class="attr">lang</span>=<span class="string">"zh-CN"</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">head</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">meta</span> <span class="attr">charset</span>=<span class="string">"utf-8"</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">meta</span> <span class="attr">name</span>=<span class="string">"viewport"</span> <span class="attr">content</span>=<span class="string">"width=device-width, initial-scale=1"</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">title</span>&gt;</span>训练营311班<span class="tag">&lt;/<span class="name">title</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">link</span> <span class="attr">href</span>=<span class="string">"../static/css/bootstrap.min.css"</span> <span class="attr">type</span>=<span class="string">'text/css'</span> <span class="attr">rel</span>=<span class="string">"stylesheet"</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">link</span> <span class="attr">href</span>=<span class="string">"../static/css/dashboard.css"</span> <span class="attr">rel</span>=<span class="string">"stylesheet"</span>&gt;</span> &#123;% block head %&#125; &#123;% endblock %&#125;</span><br><span class="line"><span class="tag">&lt;/<span class="name">head</span>&gt;</span></span><br><span class="line"></span><br><span class="line"><span class="tag">&lt;<span class="name">body</span>&gt;</span></span><br><span class="line">    <span class="comment">&lt;!--导航栏--&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">nav</span> <span class="attr">class</span>=<span class="string">"navbar navbar-inverse navbar-fixed-top"</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">div</span> <span class="attr">class</span>=<span class="string">"container-fluid"</span>&gt;</span></span><br><span class="line">            <span class="tag">&lt;<span class="name">div</span> <span class="attr">class</span>=<span class="string">"navbar-header"</span>&gt;</span></span><br><span class="line">                <span class="tag">&lt;<span class="name">button</span> <span class="attr">type</span>=<span class="string">"button"</span> <span class="attr">class</span>=<span class="string">"navbar-toggle collapsed"</span> <span class="attr">data-toggle</span>=<span class="string">"collapse"</span> <span class="attr">data-target</span>=<span class="string">"#navbar"</span> <span class="attr">aria-expanded</span>=<span class="string">"false"</span> <span class="attr">aria-controls</span>=<span class="string">"navbar"</span>&gt;</span></span><br><span class="line">                    <span class="tag">&lt;<span class="name">span</span> <span class="attr">class</span>=<span class="string">"sr-only"</span>&gt;</span>Toggle navigation<span class="tag">&lt;/<span class="name">span</span>&gt;</span></span><br><span class="line">                    <span class="tag">&lt;<span class="name">span</span> <span class="attr">class</span>=<span class="string">"icon-bar"</span>&gt;</span><span class="tag">&lt;/<span class="name">span</span>&gt;</span></span><br><span class="line">                    <span class="tag">&lt;<span class="name">span</span> <span class="attr">class</span>=<span class="string">"icon-bar"</span>&gt;</span><span class="tag">&lt;/<span class="name">span</span>&gt;</span></span><br><span class="line">                    <span class="tag">&lt;<span class="name">span</span> <span class="attr">class</span>=<span class="string">"icon-bar"</span>&gt;</span><span class="tag">&lt;/<span class="name">span</span>&gt;</span></span><br><span class="line">                <span class="tag">&lt;/<span class="name">button</span>&gt;</span></span><br><span class="line">                <span class="tag">&lt;<span class="name">a</span> <span class="attr">class</span>=<span class="string">"navbar-brand"</span> <span class="attr">href</span>=<span class="string">"/"</span>&gt;</span>销售训练营 311班<span class="tag">&lt;/<span class="name">a</span>&gt;</span></span><br><span class="line">            <span class="tag">&lt;/<span class="name">div</span>&gt;</span></span><br><span class="line">            <span class="tag">&lt;<span class="name">div</span> <span class="attr">id</span>=<span class="string">"navbar"</span> <span class="attr">class</span>=<span class="string">"navbar-collapse collapse"</span>&gt;</span></span><br><span class="line">                <span class="tag">&lt;<span class="name">ul</span> <span class="attr">class</span>=<span class="string">"nav navbar-nav"</span>&gt;</span></span><br><span class="line">                    &#123;% block menu%&#125; &#123;% endblock %&#125;</span><br><span class="line">                <span class="tag">&lt;/<span class="name">ul</span>&gt;</span></span><br><span class="line">            <span class="tag">&lt;/<span class="name">div</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;/<span class="name">div</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;/<span class="name">nav</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">div</span> <span class="attr">class</span>=<span class="string">"container-fluid"</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">div</span> <span class="attr">class</span>=<span class="string">"row"</span>&gt;</span></span><br><span class="line">            &#123;% block main%&#125; &#123;% endblock %&#125;</span><br><span class="line">        <span class="tag">&lt;/<span class="name">div</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;/<span class="name">div</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">script</span> <span class="attr">src</span>=<span class="string">"../static/js/bootstrap.min.js"</span> <span class="attr">type</span>=<span class="string">"text/javascript"</span>&gt;</span><span class="tag">&lt;/<span class="name">script</span>&gt;</span></span><br><span class="line">    &#123;% block script %&#125; &#123;% endblock %&#125;</span><br><span class="line"><span class="tag">&lt;/<span class="name">body</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">html</span>&gt;</span></span><br><span class="line">#&#125;</span><br></pre></td></tr></table></figure>
<p>可以看出页面采用的是 <a href="https://getbootstrap.com/" target="_blank" rel="noopener" title="Bootstrap 框架">Bootstrap 框架</a>，加载了 Bootstrap 必要的 Css 和 js 库。</p>
<p>然后加入了页面框架，并预留了菜单、页面主体、定制的脚本位置。</p>
<h3 id="打卡页面"><a href="#打卡页面" class="headerlink" title="打卡页面"></a>打卡页面</h3><p>打卡页面需要展示打卡率，最好的方式是用图表。</p>
<p>首选 <a href="https://echarts.apache.org/zh/index.html" target="_blank" rel="noopener" title="ECharts">ECharts</a>，因为 ECharts 很成熟，而且易用。</p>
<p>然后在 <a href="https://echarts.apache.org/examples/zh/index.html" target="_blank" rel="noopener" title="ECharts 示例">ECharts 示例</a> 中找到合适的图表。</p>
<p>值得点赞的是，ECharts 示例中，提供了示例代码，直接复制使用即可。</p>
<p>我们选用 <a href="https://echarts.apache.org/examples/zh/editor.html?c=bar-label-rotation" target="_blank" rel="noopener" title="柱状图标签旋转">柱状图标签旋转</a></p>
<p><img src="../images/2021/08/python_op_2/01.png" alt="柱状图标签旋转"></p>
<p>将代码复制到页面中。</p>
<p>图表数据通过 Flask 视图加载是提供。</p>
<p>部分代码如下：</p>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br></pre></td><td class="code"><pre><span class="line">&#123;#</span><br><span class="line">&#123;% extends "layout.html" %&#125; </span><br><span class="line">&#123;% block menu %&#125;</span><br><span class="line"><span class="tag">&lt;<span class="name">li</span> <span class="attr">class</span>=<span class="string">"active"</span>&gt;</span><span class="tag">&lt;<span class="name">a</span> <span class="attr">href</span>=<span class="string">"/check_rate"</span>&gt;</span>打卡率<span class="tag">&lt;/<span class="name">a</span>&gt;</span><span class="tag">&lt;/<span class="name">li</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">li</span>&gt;</span><span class="tag">&lt;<span class="name">a</span> <span class="attr">href</span>=<span class="string">"/memberdata"</span>&gt;</span>成员数据<span class="tag">&lt;/<span class="name">a</span>&gt;</span><span class="tag">&lt;/<span class="name">li</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">li</span>&gt;</span><span class="tag">&lt;<span class="name">a</span> <span class="attr">href</span>=<span class="string">"/teamleader"</span>&gt;</span>组长数据<span class="tag">&lt;/<span class="name">a</span>&gt;</span><span class="tag">&lt;/<span class="name">li</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">li</span>&gt;</span><span class="tag">&lt;<span class="name">a</span> <span class="attr">href</span>=<span class="string">"/sale"</span>&gt;</span>开单记录<span class="tag">&lt;/<span class="name">a</span>&gt;</span><span class="tag">&lt;/<span class="name">li</span>&gt;</span></span><br><span class="line">&#123;% endblock %&#125; </span><br><span class="line">&#123;% block main %&#125;</span><br><span class="line"><span class="tag">&lt;<span class="name">div</span> <span class="attr">class</span>=<span class="string">"col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2 main"</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">h1</span> <span class="attr">class</span>=<span class="string">"page-header"</span>&gt;</span>&#123;&#123;title&#125;&#125;<span class="tag">&lt;/<span class="name">h1</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">div</span> <span class="attr">class</span>=<span class="string">"row placeholders"</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">div</span> <span class="attr">class</span>=<span class="string">"col-xs-12 col-sm-8 col-lg-10 placeholder"</span> <span class="attr">style</span>=<span class="string">"height:500px;"</span> <span class="attr">id</span>=<span class="string">"main"</span>&gt;</span><span class="tag">&lt;/<span class="name">div</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">div</span> <span class="attr">class</span>=<span class="string">"col-lg-4 col-lg-offset-4  col-sm-6 col-sm-offset-3 col-xs-8 col-xs-offset-2"</span>&gt;</span></span><br><span class="line">            <span class="tag">&lt;<span class="name">div</span> <span class="attr">id</span>=<span class="string">"detail"</span>&gt;</span>点击图表查看 打卡详情<span class="tag">&lt;/<span class="name">div</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;/<span class="name">div</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;/<span class="name">div</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">div</span>&gt;</span></span><br><span class="line">&#123;% endblock %&#125; </span><br><span class="line">&#123;% block script %&#125;</span><br><span class="line"><span class="tag">&lt;<span class="name">script</span> <span class="attr">src</span>=<span class="string">"../static/js/jquery.2.0.3.min.js"</span> <span class="attr">type</span>=<span class="string">"text/javascript"</span>&gt;</span><span class="tag">&lt;/<span class="name">script</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">script</span> <span class="attr">src</span>=<span class="string">"../static/js/echarts5.min.js"</span> <span class="attr">charset</span>=<span class="string">"utf-8"</span>&gt;</span><span class="tag">&lt;/<span class="name">script</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">script</span> <span class="attr">type</span>=<span class="string">"text/javascript"</span>&gt;</span></span><br><span class="line"><span class="actionscript">    <span class="keyword">var</span> app = &#123;&#125;;</span></span><br><span class="line"><span class="javascript">    <span class="keyword">var</span> chartDom = <span class="built_in">document</span>.getElementById(<span class="string">'main'</span>);</span></span><br><span class="line"><span class="actionscript">    <span class="keyword">var</span> myChart = echarts.init(chartDom);</span></span><br><span class="line"></span><br><span class="line"><span class="handlebars"><span class="xml">    ...<span class="tag">&lt;<span class="name">省略</span>&gt;</span>...</span></span></span><br><span class="line"></span><br><span class="line"><span class="actionscript">    <span class="keyword">var</span> option = &#123;</span></span><br><span class="line">        title: &#123;</span><br><span class="line"><span class="actionscript">            show: <span class="literal">true</span>,</span></span><br><span class="line"><span class="actionscript">            left: <span class="string">'center'</span>,</span></span><br><span class="line"><span class="actionscript">            top: <span class="string">'top'</span></span></span><br><span class="line">        &#125;,</span><br><span class="line"><span class="handlebars"><span class="xml">        ...<span class="tag">&lt;<span class="name">省略</span>&gt;</span>...</span></span></span><br><span class="line">        dataset: &#123;</span><br><span class="line"><span class="handlebars"><span class="xml">            source: </span><span class="template-variable">&#123;&#123; data | safe &#125;&#125;</span></span></span><br><span class="line">        &#125;,</span><br><span class="line"><span class="handlebars"><span class="xml">        ...<span class="tag">&lt;<span class="name">省略</span>&gt;</span>...</span></span></span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line"><span class="handlebars"><span class="xml">    ...<span class="tag">&lt;<span class="name">省略</span>&gt;</span>...</span></span></span><br><span class="line">&#123;% endblock %&#125; </span><br><span class="line">#&#125;</span><br></pre></td></tr></table></figure>
<ul>
<li>引入模板页面 <code>layout.html</code></li>
<li>等 为替换的内容</li>
<li>的意思是 使用视图中的值 <code>data</code> 填充到这里，后面的 <code>safe</code> 是一个过滤器，表示替换部分不做 Html 安全字符转化</li>
</ul>
<h4 id="数据缩放"><a href="#数据缩放" class="headerlink" title="数据缩放"></a>数据缩放</h4><p>这里还需要解决一个问题，就是随着日期的增加，图表就是很密，不好观看，ECharts 提供一种图表缩放工具 <code>DataZoom</code>,</p>
<p>可以通过拖动和改变大小控制数据的展示范围，配置很简单，加在图表的配置中就好了，例如我的写法是：</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">dataZoom: [&#123;</span><br><span class="line">    type: <span class="string">'slider'</span>,</span><br><span class="line">    start: <span class="number">60</span>,</span><br><span class="line">    end: <span class="number">100</span></span><br><span class="line">&#125;],</span><br></pre></td></tr></table></figure>
<ul>
<li><code>start</code> 和 <code>end</code> 表示数据范围开始和结束的百分比，这一点特别赞</li>
</ul>
<h4 id="详细数据"><a href="#详细数据" class="headerlink" title="详细数据"></a>详细数据</h4><p>图表展示后，如果想知道某一天某个组详细的打卡数据怎么办？</p>
<p>为了便于使用，利用 EChart 的事件机制，当点击一个柱状图时，显示出详细信息。</p>
<p>实现很简单，就是个图表对象加载一个事件，载事件里，使用 <a href="https://developer.mozilla.org/zh-CN/docs/Web/Guide/AJAX" target="_blank" rel="noopener" title="Ajax">Ajax</a> 加载并显示数据就好：</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br></pre></td><td class="code"><pre><span class="line">myChart.on(<span class="string">'click'</span>, <span class="string">'series'</span>, <span class="function"><span class="keyword">function</span>(<span class="params">params</span>) </span>&#123;</span><br><span class="line">    <span class="built_in">console</span>.log(params);</span><br><span class="line">    $.ajax(&#123;</span><br><span class="line">        url: <span class="string">"/api/teamcheckdetail"</span>,</span><br><span class="line">        data: &#123;</span><br><span class="line">            team: params.seriesName,</span><br><span class="line">            date: params.name</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;).done(<span class="function"><span class="keyword">function</span>(<span class="params">response</span>) </span>&#123;</span><br><span class="line">        data = response.data;</span><br><span class="line">        $(<span class="string">"#detail"</span>).jsGrid(&#123;</span><br><span class="line">            editing: <span class="literal">false</span>,</span><br><span class="line">            sorting: <span class="literal">false</span>,</span><br><span class="line">            autoload: <span class="literal">false</span>,</span><br><span class="line">            data: data,</span><br><span class="line">            fields: [&#123;</span><br><span class="line">                <span class="string">'name'</span>: <span class="string">'name'</span>,</span><br><span class="line">                <span class="string">'title'</span>: <span class="string">'昵称'</span></span><br><span class="line">            &#125;, &#123;</span><br><span class="line">                <span class="string">'name'</span>: <span class="string">'check'</span>,</span><br><span class="line">                <span class="string">'title'</span>: <span class="string">'打卡'</span></span><br><span class="line">            &#125;]</span><br><span class="line">        &#125;);</span><br><span class="line">    &#125;);</span><br><span class="line">&#125;);</span><br></pre></td></tr></table></figure>
<ul>
<li>事件争对于 <code>系列</code>(series) 被点击</li>
<li><code>/api/teamcheckdetail</code> 为后台数据接口（详见 API 设计）</li>
<li><code>$(&quot;#detail&quot;).jsGrid()</code> 是一个 jsGrid 做的表格，加载方法是重新炫耀一个表格</li>
</ul>
<p>到此，最复杂的打卡页面就搞定了，看看效果吧：</p>
<p><img src="../images/2021/08/python_op_2/02.png" alt="打卡率"></p>
<h3 id="数据列表"><a href="#数据列表" class="headerlink" title="数据列表"></a>数据列表</h3><p>成员数据、组长数据 以及 开单数据，都是用数据表格展示的，使用了 <a href="http://js-grid.com/getting-started/" target="_blank" rel="noopener" title="jsGrid">jsGrid</a> 框架，主要是方便易用。</p>
<p>在页面上定义一个 <code>div</code>，并设置 id，然后用 jsGrid 方法渲染一些就可以了，和简单。</p>
<p>其实在上一节，我们以及看到如何渲染了，需要做的事定义后台 API 接口，通过 Ajax 加载数据就可以了：</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br></pre></td><td class="code"><pre><span class="line">$(<span class="string">"#jsGrid"</span>).jsGrid(&#123;</span><br><span class="line">    height: <span class="string">'600'</span>,</span><br><span class="line">    width: <span class="string">"100%"</span>,</span><br><span class="line">    editing: <span class="literal">false</span>,</span><br><span class="line">    sorting: <span class="literal">false</span>,</span><br><span class="line">    autoload: <span class="literal">true</span>,</span><br><span class="line">    controller: &#123;</span><br><span class="line">        loadData: <span class="function"><span class="keyword">function</span>(<span class="params"></span>) </span>&#123;</span><br><span class="line">            <span class="keyword">var</span> d = $.Deferred();</span><br><span class="line">            $.ajax(&#123;</span><br><span class="line">                url: <span class="string">"/api/memberdata"</span>,</span><br><span class="line">            &#125;).done(<span class="function"><span class="keyword">function</span>(<span class="params">response</span>) </span>&#123;</span><br><span class="line">                d.resolve(response.data);</span><br><span class="line">            &#125;);</span><br><span class="line">            <span class="keyword">return</span> d.promise();</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;,</span><br><span class="line">    fields: [&#123;<span class="string">'name'</span>: <span class="string">'组'</span>, <span class="attr">type</span>: <span class="string">"text"</span>&#125;,</span><br><span class="line">        &#123;<span class="string">'name'</span>:<span class="string">'昵称'</span>, <span class="attr">type</span>: <span class="string">"text"</span>&#125;,</span><br><span class="line">        &#123;<span class="string">'name'</span>:<span class="string">'开单'</span>, <span class="attr">type</span>: <span class="string">"text"</span>&#125;,</span><br><span class="line">        &#123;<span class="string">'name'</span>:<span class="string">'分享'</span>, <span class="attr">type</span>: <span class="string">"text"</span>&#125;,</span><br><span class="line">        &#123;<span class="string">'name'</span>:<span class="string">'打卡'</span>, <span class="attr">type</span>: <span class="string">"text"</span>&#125;,</span><br><span class="line">        &#123;<span class="string">'name'</span>:<span class="string">'提问'</span>, <span class="attr">type</span>: <span class="string">"text"</span>&#125;,</span><br><span class="line">        &#123;<span class="string">'name'</span>:<span class="string">'解答整理'</span>, <span class="attr">type</span>: <span class="string">"text"</span>&#125;,</span><br><span class="line">        &#123;<span class="string">'name'</span>:<span class="string">'积分'</span>, <span class="attr">type</span>: <span class="string">"text"</span>&#125;,</span><br><span class="line">    ]</span><br><span class="line">&#125;);</span><br></pre></td></tr></table></figure>
<ul>
<li><code>controller</code> 里的 <code>loadData</code> 在页面元素绘制完成调用</li>
<li><code>loadData</code> 方法返回一个 <a href="https://es6.ruanyifeng.com/#docs/promise" target="_blank" rel="noopener" title="promise 对象">promise</a>，等数据获取成功之后，会渲染到页面上</li>
</ul>
<p>那么 组长数据 和 开单数据 是类似的，就不赘述了。</p>
<h2 id="数据接口"><a href="#数据接口" class="headerlink" title="数据接口"></a>数据接口</h2><p>Flask 实现后台接口，特别简单，只需要再接口相应方法前，加句<a href="https://www.jianshu.com/p/7a644520418b" target="_blank" rel="noopener" title="Python 注解">注解</a> 就好了，例如 打卡率的接口：</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@app.route('/')</span></span><br><span class="line"><span class="meta">@app.route('/check_rate')</span></span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">check_rate</span><span class="params">()</span>:</span></span><br><span class="line">    data = dataSource.show_check_rate(rtype=<span class="string">'dict'</span>)</span><br><span class="line">    ret = [[<span class="string">'date'</span>, <span class="string">'1组'</span>, <span class="string">'2组'</span>, <span class="string">'3组'</span>, <span class="string">'4组'</span>, <span class="string">'5组'</span>]]</span><br><span class="line">    <span class="keyword">for</span> d <span class="keyword">in</span> data:</span><br><span class="line">        row = []</span><br><span class="line">        <span class="keyword">for</span> k <span class="keyword">in</span> d:</span><br><span class="line">            row.append(d[k])</span><br><span class="line">        ret.append(row)</span><br><span class="line">    <span class="keyword">return</span> render_template(<span class="string">'check_rate.html'</span>, title=<span class="string">'打卡率'</span>, data=ret)</span><br></pre></td></tr></table></figure>
<ul>
<li><code>@app.route</code> 是个注解，以指定 URL 路径，由 <code>check_rate</code> 方法做相应</li>
<li><code>dataSource</code> 是对上一期数据处理功能的一个封装，调用相应方法，获取数据</li>
<li><code>render_template</code> 是 Flask 响应页面合成的方法，第一个参数是模板页面，后面的命名参数是需要替换的数据</li>
</ul>
<p>打卡率页面的数据，是合成响应页面时提供的，还有一些页面需要前台通过 Ajax 方式获取，接口怎么写呢？</p>
<p>用获取成员数据作为例子：</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@app.route('/api/memberdata')</span></span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">api_memberdata</span><span class="params">()</span>:</span></span><br><span class="line">    data = &#123;<span class="string">'data'</span>: dataSource.show_member_score(rtype=<span class="string">'dict'</span>)&#125;</span><br><span class="line">    <span class="keyword">return</span> jsonify(data)</span><br></pre></td></tr></table></figure>
<ul>
<li>通过封装的数据处理类，得到数据</li>
<li>调用 Flask 的 <code>jsonify</code> 方法将数据作为 json 响应提供给前台</li>
</ul>
<p>那么，其他的页面响应和数据响应接口是类似的，更详细的代码，见代码示例。</p>
<h2 id="部署"><a href="#部署" class="headerlink" title="部署"></a>部署</h2><p>主要的开发工作完成后，就可以部署了。</p>
<p>之前写过 <a href="https://mp.weixin.qq.com/s/b9Mmp0bSCmNVDzaExJlJ0w" target="_blank" rel="noopener" title="部署 Flask">部署 Flask</a>，用的是 <a href="https://uwsgi-docs.readthedocs.io/en/latest/" target="_blank" rel="noopener">uWSGI</a> ，刚好照搬。</p>
<p>如果没有 git 或者 svn 的代码管理，就直接将复制到服务器上，安装 Flask，就可以启动了。</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">python app.py</span><br></pre></td></tr></table></figure>
<p>没有问题，配置一下 <a href="https://www.nginx.com/" target="_blank" rel="noopener" title="Nginx">Nginx</a> 的反向代理:</p>
<figure class="highlight nginx"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="section">server</span> &#123;</span><br><span class="line">    <span class="attribute">listen</span>        <span class="number">80</span>;</span><br><span class="line">    <span class="attribute">server_name</span> stc.example.com;</span><br><span class="line">    <span class="attribute">access_log</span>    /var/log/nginx/access_stc.log main;</span><br><span class="line">    <span class="attribute">location</span> / &#123;</span><br><span class="line">        <span class="attribute">proxy_buffers</span> <span class="number">8</span> <span class="number">1024k</span>;</span><br><span class="line">        <span class="attribute">proxy_buffer_size</span> <span class="number">1024k</span>;</span><br><span class="line">        <span class="attribute">proxy_pass</span> http://127.0.0.1:5000;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<ul>
<li><code>server_name</code> 为域名，也就是通过这个地址可以访问到系统的，在此之前需要<a href="https://baike.baidu.com/item/%E5%9F%9F%E5%90%8D%E5%A4%87%E6%A1%88/1131453" target="_blank" rel="noopener" title="域名备案">申请并备案域名</a></li>
<li><code>location</code> 里的 proxy_pass 是服务器上我们的 Web 服务的地址</li>
<li>Nginx 的作用是做一个代理，将通过 stc.example.com 的访问转发到 真是地址上</li>
</ul>
<p>配置完成之后，重启一下 Nginx 服务，如果没有问题，就可以通过设置的域名访问了。</p>
<h2 id="维护"><a href="#维护" class="headerlink" title="维护"></a>维护</h2><p>开发部署完成，还不是真的完成，还需要做运维。</p>
<p>以这个项目为例，运维工作主要有两部分：</p>
<ol>
<li>数据处理</li>
<li>服务器维护</li>
</ol>
<p>只有不断地做数据处理，才能及时更新数据，这个工作对于 Web 系统来说，属于支撑性的，所以没必要让 Web 系统来负责。</p>
<p>在 Linux 系统上，有个 <a href="https://www.runoob.com/linux/linux-comm-crontab.html" target="_blank" rel="noopener" title="crontab">crontab</a> 命令，用它做定时数据数据，好处是开发量少，另外不会因为 Web 系统的问题导致数据处理不及时。</p>
<p>服务器维护，就是保证服务器不会因为异常停止工作，一般使用像 uWSGI 类的服务器都有自维护功能，如果没有使用的话，就需要自己处理了，比如写个监控脚本，当发现服务器不工作时，重启服务，并发送通知。</p>
<blockquote>
<p><strong>强烈建议</strong> 使用安全的 Web 服务器，特别是在生产环境中</p>
</blockquote>
<h2 id="总结"><a href="#总结" class="headerlink" title="总结"></a>总结</h2><p>到此，系统的搭建完成了，再也不用我每天为生成报表耗费时间了，可以将更多的时间用在更重要的事情上了。</p>
<p>如果你认真读了，就会发现，每一块的知识技术，都是很简单的，但如何将这些简单的点拼接起来，是需要大量的知识记录和历练的。</p>
<p>而我之所以可以这样做，是因为在这里的长期输出，从最基础的 Web 系统开始，一点一点了解整个 Web 系统需要的基础，当需要完成一个系统时，大部分都是来自平时的积累。</p>
<p>期望这篇文章对你有所启发，一切都源自持续积累，比心！</p>

    </div>

    
    
    

      <footer class="post-footer">
          <div class="post-tags">
              <a href="/tags/Python/" rel="tag"># Python</a>
              <a href="/tags/%E7%BC%96%E7%A8%8B/" rel="tag"># 编程</a>
          </div>

        

			<div id="wechat_subscriber" style="display: block; padding: 10px 0; margin: 20px auto; width: 100%; text-align: center">
    <img id="wechat_subscriber_qcode" src="/images/wechat-qcode.png" alt="太阳雪 wechat" style="width: 200px; max-width: 100%;"/>
    <div>关注我，获得更多精彩内容</div>
</div>

        
		
    <div class="post-nav">
      <div class="post-nav-item">
    <a href="/2021-08-09-python-op/" rel="prev" title="搞定运营，我用 Python">
      <i class="fa fa-chevron-left"></i> 搞定运营，我用 Python
    </a></div>
      <div class="post-nav-item">
    <a href="/2021-08-20-moments-note/" rel="next" title="如何优雅地经营朋友圈">
      如何优雅地经营朋友圈 <i class="fa fa-chevron-right"></i>
    </a></div>
    </div>
      </footer>
    
  </article>
  
  
  



          </div>
          
    <div class="comments" id="valine-comments"></div>

<script>
  window.addEventListener('tabs:register', () => {
    let { activeClass } = CONFIG.comments;
    if (CONFIG.comments.storage) {
      activeClass = localStorage.getItem('comments_active') || activeClass;
    }
    if (activeClass) {
      let activeTab = document.querySelector(`a[href="#comment-${activeClass}"]`);
      if (activeTab) {
        activeTab.click();
      }
    }
  });
  if (CONFIG.comments.storage) {
    window.addEventListener('tabs:click', event => {
      if (!event.target.matches('.tabs-comment .tab-content .tab-pane')) return;
      let commentClass = event.target.classList[1];
      localStorage.setItem('comments_active', commentClass);
    });
  }
</script>

        </div>
          
  
  <div class="toggle sidebar-toggle">
    <span class="toggle-line toggle-line-first"></span>
    <span class="toggle-line toggle-line-middle"></span>
    <span class="toggle-line toggle-line-last"></span>
  </div>

  <aside class="sidebar">
    <div class="sidebar-inner">

      <ul class="sidebar-nav motion-element">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <!--noindex-->
      <div class="post-toc-wrap sidebar-panel">
          <div class="post-toc motion-element"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#规划"><span class="nav-number">1.</span> <span class="nav-text">规划</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#展示页面"><span class="nav-number">2.</span> <span class="nav-text">展示页面</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#模板页面"><span class="nav-number">2.1.</span> <span class="nav-text">模板页面</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#打卡页面"><span class="nav-number">2.2.</span> <span class="nav-text">打卡页面</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#数据缩放"><span class="nav-number">2.2.1.</span> <span class="nav-text">数据缩放</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#详细数据"><span class="nav-number">2.2.2.</span> <span class="nav-text">详细数据</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#数据列表"><span class="nav-number">2.3.</span> <span class="nav-text">数据列表</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#数据接口"><span class="nav-number">3.</span> <span class="nav-text">数据接口</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#部署"><span class="nav-number">4.</span> <span class="nav-text">部署</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#维护"><span class="nav-number">5.</span> <span class="nav-text">维护</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#总结"><span class="nav-number">6.</span> <span class="nav-text">总结</span></a></li></ol></div>
      </div>
      <!--/noindex-->

      <div class="site-overview-wrap sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
    <img class="site-author-image" itemprop="image" alt="太阳雪"
      src="/images/avatar.png">
  <p class="site-author-name" itemprop="name">太阳雪</p>
  <div class="site-description" itemprop="description">总结 技术 思考 想法</div>
</div>
<div class="site-state-wrap motion-element">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
          <a href="/archives/">
        
          <span class="site-state-item-count">88</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
            <a href="/categories/">
          
        <span class="site-state-item-count">14</span>
        <span class="site-state-item-name">分类</span></a>
      </div>
      <div class="site-state-item site-state-tags">
            <a href="/tags/">
          
        <span class="site-state-item-count">47</span>
        <span class="site-state-item-name">标签</span></a>
      </div>
  </nav>
</div>



      </div>

    </div>
  </aside>
  <div id="sidebar-dimmer"></div>


      </div>
    </main>

    <footer class="footer">
      <div class="footer-inner">
        

        

<div class="copyright">
  
  &copy; 
  <span itemprop="copyrightYear">2022</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">太阳雪</span>
</div>
  <div class="powered-by">由 <a href="https://hexo.io/" class="theme-link" rel="noopener" target="_blank">Hexo</a> & <a href="https://mist.theme-next.org/" class="theme-link" rel="noopener" target="_blank">NexT.Mist</a> 强力驱动
  </div>

        








      </div>
    </footer>
  </div>

  
  <script src="/lib/anime.min.js"></script>
  <script src="/lib/velocity/velocity.min.js"></script>
  <script src="/lib/velocity/velocity.ui.min.js"></script>

<script src="/js/utils.js"></script>

<script src="/js/motion.js"></script>


<script src="/js/schemes/muse.js"></script>


<script src="/js/next-boot.js"></script>




  
  <script>
    (function(){
      var canonicalURL, curProtocol;
      //Get the <link> tag
      var x=document.getElementsByTagName("link");
		//Find the last canonical URL
		if(x.length > 0){
			for (i=0;i<x.length;i++){
				if(x[i].rel.toLowerCase() == 'canonical' && x[i].href){
					canonicalURL=x[i].href;
				}
			}
		}
    //Get protocol
	    if (!canonicalURL){
	    	curProtocol = window.location.protocol.split(':')[0];
	    }
	    else{
	    	curProtocol = canonicalURL.split(':')[0];
	    }
      //Get current URL if the canonical URL does not exist
	    if (!canonicalURL) canonicalURL = window.location.href;
	    //Assign script content. Replace current URL with the canonical URL
      !function(){var e=/([http|https]:\/\/[a-zA-Z0-9\_\.]+\.baidu\.com)/gi,r=canonicalURL,t=document.referrer;if(!e.test(r)){var n=(String(curProtocol).toLowerCase() === 'https')?"https://sp0.baidu.com/9_Q4simg2RQJ8t7jm9iCKT-xh_/s.gif":"//api.share.baidu.com/s.gif";t?(n+="?r="+encodeURIComponent(document.referrer),r&&(n+="&l="+r)):r&&(n+="?l="+r);var i=new Image;i.src=n}}(window);})();
  </script>















  

  


<script>
NexT.utils.loadComments(document.querySelector('#valine-comments'), () => {
  NexT.utils.getScript('//unpkg.com/valine/dist/Valine.min.js', () => {
    var GUEST = ['nick', 'mail', 'link'];
    var guest = 'nick,mail';
    guest = guest.split(',').filter(item => {
      return GUEST.includes(item);
    });
    new Valine({
      el         : '#valine-comments',
      verify     : false,
      notify     : false,
      appId      : 'teRj7yeJj0xpfGKLJ5uFdbIu-gzGzoHsz',
      appKey     : '3uie0p1nxouCCnkjiXTEBeLd',
      placeholder: "您的关注是我的动力",
      avatar     : 'mm',
      meta       : guest,
      pageSize   : '10' || 10,
      visitor    : true,
      lang       : 'zh-cn' || 'zh-cn',
      path       : location.pathname,
      recordIP   : false,
      serverURLs : ''
    });
  }, window.Valine);
});
</script>

</body>
</html>
